<?php

use \Carbon\Carbon;

class HomeController extends BaseController {
    public function index(){

        $weatherapi = file_get_contents('http://weatherapi.aliapp.com/?area=101210401', true);
        $weatherdata = json_decode($weatherapi);

        $now = Carbon::now();
        $registed_at = new Carbon(Auth::user()->created_at);
        $ruzhi_time = $registed_at->diff($now)->days;
        $current_user_projects_count = Auth::user()->projects()->remember(30)->count();
        $current_user_reports_count = Auth::user()->reports()->remember(30)->count();

        $user_info = compact('ruzhi_time', 'current_user_projects_count', 'current_user_reports_count');

        return Response::json(compact('weatherdata', 'user_info'), 200);
    }
}
